﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

public class H5HuoDong : MonoBehaviour
{
    private int initHeight;
    private int initWidth;

#if UNITY_ANDROID

    private void Update()
    {
        if (initHeight != Screen.height || initWidth != Screen.width)
        {
            initWidth = Screen.height;
            initHeight = Screen.width;
            UniWebView webView = GetComponent<UniWebView>();
            webView.Reload();
        }
    }

    void ReShow()
    {
        UniWebView webView = GetComponent<UniWebView>();
        webView.Show();
    }

    private void OnApplicationPause()
    {
        UniWebView webView = GetComponent<UniWebView>();
        webView.Hide();
    }

    private void OnApplicationFocus()
    {
        Invoke("ReShow",0.5f);
    }

    [Serializable]
    public class RoleInfo
    {
        public string roleId;
        public string roleName;
        public string serverId;
        public string serverName;
        public string userId;
        public string roleLevel;
    }
    public void Awake()
    {

        initWidth = Screen.height;
        initHeight = Screen.width;
    }
    string strURL = "https://zhzr.uwan.com/t2/227/5609.html?cdid=";
    private void Start()
    {
        RoleInfo roleInfo = new RoleInfo();
        roleInfo.roleId = "140040603";
        roleInfo.roleName = "2048";
        roleInfo.serverId = "210015";
        roleInfo.serverName = "官网混服S15";
        roleInfo.userId = "01000100000000000000000000000000222546288";
        roleInfo.roleLevel = "665";
        string json = JsonUtility.ToJson(roleInfo);
        byte[] bytes = Encoding.UTF8.GetBytes(json);
        InitAddress(strURL + Convert.ToBase64String(bytes));
    }
    public void InitAddress(string address)
    {
        UniWebView webView = GetComponent<UniWebView>();
        webView.OnLoadComplete += OnLoadComplete;
        webView.InsetsForScreenOreitation += InsetsForScreenOreitation;
        webView.url = address;
        webView.Load();
        webView.zoomEnable = false;
        webView.backButtonEnable = false;
    }

    private UniWebViewEdgeInsets InsetsForScreenOreitation(UniWebView webView, UniWebViewOrientation orientation)
    {

        return new UniWebViewEdgeInsets((int)(0.12*(float)Screen.height), (int)(0.083 * (float)Screen.width), (int)(0.05 * (float)Screen.height),(int)(0.083 * (float)Screen.width));
    }

   

    private void OnLoadComplete(UniWebView webView, bool success, string errorMessage)
    {
        if (success)
        {
            webView.Show();
        }
    }


#endif

}
